<template>
	<view>
		<view class="Demo">
			<view>
				效果演示
			</view>
			<button @click="oneClickWifi">一键WIFI</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {

			}
		},
		methods: {
			oneClickWifi() {
				// 获取手机型号
				let that = this
				uni.getSystemInfo({
					success: (res) => {
						let system = ''
						console.log("当前手机型号===>",res)
						if (res.platform == 'android') {
							system = parseInt(res.platform.substr(8))
						}
						if (res.platform == 'ios') {
							system = parseInt(res.platform.substr(4))
						}
						if (res.platform == 'android' && system < 6) {
							uni.showToast({
								title: '手机版本不支持',
								icon: 'none'
							})
							return
						}
						if (res.platform == 'ios' && system < 11.2) {
							uni.showToast({
								title: '手机版本不支持',
								icon: 'none'
							})
							return
						}
						//初始wifi模块
						that.start_wifi()
					}
				})
			},
			// // 初始化Wi-Fi模块
			start_wifi() {
				let that = this
				uni.startWifi({
					success: (res) => {
						console.log("startWifi==>", res)
						that.connected()
					},
					fail: (error) => {
						console.log("初始化失败==>", error)
						uni.showToast({
							title: '链接失败',
							icon: 'error'
						})
					}
				})
			},
			// 连接 Wi-Fi
			connected() {
				let that = this
				uni.connectWifi({
					SSID: 'Chicony-guest', //Wi-Fi 设备名称
					password: 'vip888888', //Wi-Fi 密码
					success: (res) => {
						console.log('wifi链接成功==>', res);
						uni.showToast({
							title: "链接成功"
						})
					},
					fail: (error) => {
						console.log("wifi链接失败==>", error)
						uni.showToast({
							title: '链接失败',
							icon: 'error'
						})
					}
				})
			}
		}
	}
</script>

<style>
</style>